package com.shen.accountbook.bean.temp;

import android.os.Parcel;
import android.os.Parcelable;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Keep;
import org.greenrobot.greendao.annotation.ToOne;
import org.greenrobot.greendao.annotation.Unique;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.DaoException;
import com.shen.accountbook.greendao.DaoSession;
import com.shen.accountbook.greendao.FirstSortBeanDao;
import com.shen.accountbook.greendao.SecondSortBeanDao;

import java.util.List;

/**
 * author:  shen
 * date:    2018/8/30
 *
 * 第二级分类 --
 */
@Entity
public class SecondSortBean implements Parcelable {

    @Id
    private Long id;

    /** "支出/收入"一级分类的ID */
    private Long first_sort_id;
    @ToOne(joinProperty = "first_sort_id")
    private FirstSortBean firstSortBean;


    /** "支出/收入"ID */
    @Unique
    private Long second_sort_id;
    /** "支出/收入"名称 */
    private String second_sort_name;

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    @Generated(hash = 314324506)
    private transient SecondSortBeanDao myDao;



    @Generated(hash = 1161710588)
    public SecondSortBean(Long id, Long first_sort_id, Long second_sort_id,
            String second_sort_name) {
        this.id = id;
        this.first_sort_id = first_sort_id;
        this.second_sort_id = second_sort_id;
        this.second_sort_name = second_sort_name;
    }
    @Generated(hash = 1032166371)
    public SecondSortBean() {
    }

    @Generated(hash = 1140376590)
    private transient Long firstSortBean__resolvedKey;



    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Long getFirst_sort_id() {
        return this.first_sort_id;
    }
    public void setFirst_sort_id(Long first_sort_id) {
        this.first_sort_id = first_sort_id;
    }

    public Long getSecond_sort_id() {
        return second_sort_id;
    }

    public void setSecond_sort_id(Long second_sort_id) {
        this.second_sort_id = second_sort_id;
    }

    public String getSecond_sort_name() {
        return second_sort_name;
    }

    public void setSecond_sort_name(String second_sort_name) {
        this.second_sort_name = second_sort_name;
    }
    /** To-one relationship, resolved on first access. */
    @Generated(hash = 575747550)
    @Keep
    public FirstSortBean getFirstSortBean() {
        Long __key = this.first_sort_id;
        if (firstSortBean__resolvedKey == null
                || !firstSortBean__resolvedKey.equals(__key)) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            FirstSortBeanDao targetDao = daoSession.getFirstSortBeanDao();

            FirstSortBean firstSortBeanNew = null;
            List<FirstSortBean> list = targetDao.queryBuilder()
                    .where(FirstSortBeanDao.Properties.First_sort_id.eq(__key)).list();

            if(list != null && list.size() > 0){
                firstSortBeanNew = list.get(0);
            }
            synchronized (this) {
                firstSortBean = firstSortBeanNew;
                firstSortBean__resolvedKey = __key;
            }
        }
        return firstSortBean;
    }
    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1417820822)
    public void setFirstSortBean(FirstSortBean firstSortBean) {
        synchronized (this) {
            this.firstSortBean = firstSortBean;
            first_sort_id = firstSortBean == null ? null : firstSortBean.getId();
            firstSortBean__resolvedKey = first_sort_id;
        }
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }
    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1244521698)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getSecondSortBeanDao() : null;
    }

    @Override
    public String toString() {
        return "SecondSortBean{" +
                "id=" + id +
                ", first_sort_id=" + first_sort_id +
                ", firstSortBean=" + firstSortBean +
                ", second_sort_id=" + second_sort_id +
                ", second_sort_name='" + second_sort_name + '\'' +
                ", daoSession=" + daoSession +
                ", myDao=" + myDao +
                ", firstSortBean__resolvedKey=" + firstSortBean__resolvedKey +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeValue(this.id);
        dest.writeValue(this.first_sort_id);
        dest.writeParcelable(this.firstSortBean, flags);
        dest.writeValue(this.second_sort_id);
        dest.writeString(this.second_sort_name);
    }

    protected SecondSortBean(Parcel in) {
        this.id = (Long) in.readValue(Long.class.getClassLoader());
        this.first_sort_id = (Long) in.readValue(Long.class.getClassLoader());
        this.firstSortBean = in.readParcelable(FirstSortBean.class.getClassLoader());
        this.second_sort_id = (Long) in.readValue(Long.class.getClassLoader());
        this.second_sort_name = in.readString();
    }

    public static final Parcelable.Creator<SecondSortBean> CREATOR = new Parcelable.Creator<SecondSortBean>() {
        @Override
        public SecondSortBean createFromParcel(Parcel source) {
            return new SecondSortBean(source);
        }

        @Override
        public SecondSortBean[] newArray(int size) {
            return new SecondSortBean[size];
        }
    };
}
